/*
 * @Description: 分货调整DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2021-02-24 11:56:54
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-25 14:31:33
 */
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';
import { resetMonth } from '../utils/utilsFun';
import intl from 'utils/intl';
const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;
const O2_CM = process.env.NODE_ENV === 'development' ? '/o2cp' : commonConfigStore.O2_CM;

const distributionAdjustmentDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            const { data } = config;
            const { adjustmentMonth } = data;
            // 截掉月份后面的时间
            const submitData = resetMonth(data,adjustmentMonth,'adjustmentMonth')
            return {
                ...config,
                data: {
                    ...submitData,
                },
                url: `${O2_OM}/v1/adjustments`,
                method: 'get',
            };
        },
        destroy: config => {
            return {
                ...config,
                data: config.data[0],
                url: `${O2_OM}/v1/adjustments`,
                method: 'delete',
            };
        },
    },
    fields: [
        {
            name: 'adjustmentCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentCode').d('调整单号'),
            required: true,
        },
        {
            name: 'adjustmentReason',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentReason').d('调整原因'),
            required: true,
        },
        {
            name: 'adjustmentMonth',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentMonth').d('调整月份'),
            required: true,
        },
        {
            name: 'adjustmentType',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentType').d('调整类型'),
            required: true,
            lookupCode: 'DJISM.ADJUSTMENT_TYPE'
        },
        {
            name: 'businessGroupMeaning',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
        },
        {
            name: 'adjustmentStatus',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.checkRuleStatusCode').d('状态'),
            lookupCode: 'DJISM.ADJUSTMENT_STATUS'
        },
        {
            name: 'createdByAd',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.createdUserName').d('创建人'),
        },
        {
            name: 'creationDate',
            type: FieldType.dateTime,
            label: intl.get('dji.otc.om.view.field.creationDate').d('创建时间'),
        },
    ],
    queryFields: [
        {
            name: 'adjustmentCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentCode').d('调整单号'),
        },
        {
            name: 'dateObj',
            type: FieldType.date,
            label: intl.get('dji.otc.om.view.field.documentTime').d('单据时间'),
            range: ['start', 'end'],
            ignore: 'always',
        },
        {
            name: 'creationDateFrom',
            type: FieldType.date,
            bind: 'dateObj.start',
        },
        {
            name: 'creationDateTo',
            type: FieldType.date,
            bind: 'dateObj.end',
        },
        {
            label: intl.get('dji.otc.om.view.field.outAreaName').d('调出小区'),
            labelWidth: 120,
            name: 'outAreaObj',
            type: FieldType.object,
            checkValueOnOptionsChange: true,
            lookupUrl: `${O2_CM}/v1/cm-contract-permissions/get-area-info`,
            ignore: 'always',
        },
        {
            label: intl.get('dji.otc.om.view.field.intoAreaName').d('调入小区'),
            labelWidth: 120,
            name: 'intoAreaObj',
            type: FieldType.object,
            checkValueOnOptionsChange: true,
            lookupUrl: `${O2_CM}/v1/cm-contract-permissions/get-area-info`,
            ignore: 'always',
        },
        {
            name: 'outAreaId',
            bind: 'outAreaObj.value',
            type: FieldType.string,
        },
        {
            name: 'intoAreaId',
            bind: 'intoAreaObj.value',
            type: FieldType.string,
        },
        {
            name: 'adjustmentType',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.adjustmentType').d('调整类型'),
            lookupCode: 'DJISM.ADJUSTMENT_TYPE'
        },
        {
            name: 'adjustmentMonth',
            type: FieldType.month,
            label: intl.get('dji.otc.om.view.field.adjustmentMonth').d('调整月份'),
        },
        {
            name: 'adjustmentStatus',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.checkRuleStatusCode').d('状态'),
            lookupCode: 'DJISM.ADJUSTMENT_STATUS'
        },
    ],
});

const resultDetailDS = () => ({
    autoCreate: true,
    dataToJSON: 'normal',
    transport: {
        submit: config => {
            return {
                ...config,
                data: config.data[0],
                url: `${O2_OM}/v1/quota-plans/confirm`,
                method: 'POST',
            };
        },
    },
    fields: [
        {
            name: 'createTime',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.importTime').d('导入时间'),
            required: true,
        },
        {
            name: 'importMode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.importMode').d('导入方式'),
            required: true,
        },
        {
            name: 'quantity ',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.importQuantity').d('导入数量'),
            required: true,
        },
    ],
});

export { distributionAdjustmentDS, resultDetailDS };
